﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using SMSROUTER.Business;
using Utils;
using Settings;

namespace SMSROUTER.UI
{
    public partial class Register : BasePage
    {
        DBDataContext DB = new DBDataContext(AppSetting.ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDataDropdownList();
            }
        }

        protected void btnCreateUser_Click(object sender, EventArgs e)
        {
            SysUser user = new SysUser();
            user.UserName = txtUserName.Text;
            user.Email = txtEmail.Text;
            user.Password = txtPassword.Text.Trim().ToMD5Hash();
            user.CreatedDate = DateTime.Now;
            user.Disabled = false;
            //user.UnitID = new Guid(ddlUnit.SelectedValue);
            DB.SysUsers.InsertOnSubmit(user);
            DB.SubmitChanges();
        }

        private void BindDataDropdownList()
        {
            //ddlUnit.DataSource = DB.pepsi_Units.OrderBy(p => p.Name);
            ddlUnit.DataValueField = "ID";
            ddlUnit.DataTextField = "Name";
            ddlUnit.DataBind();
        }
    }
}
